import { MessageOutlined, SettingOutlined, ReadOutlined } from '@ant-design/icons';
import { Menu, Switch } from 'antd';
import React, { useState } from 'react';
function getItem(label, key, icon, children, type) {
  return {
    key,
    icon,
    children,
    label,
    type,
  };
}
const items = [
  getItem('前言', '1', <MessageOutlined />),
  getItem('待定1', '2', <SettingOutlined />),
  getItem('待定2', '3', <SettingOutlined />),
  getItem('课程', 'sub1', <ReadOutlined />, [
    getItem('C语言程序设计', '4'),
    getItem('程序设计专题', '5'),
    getItem('离散数学及其应用', '6'),
    getItem('数据结构', '7'),
    getItem('高级数据结构与算法分析', '8'),
    getItem('数字逻辑设计', '9'),
    getItem('信息安全原理', '10'),
    getItem('计算机系统原理', '11'),
    getItem('计算机组成', '12'),
    getItem('面向对象程序设计', '13'),
    getItem('数据库系统', '14'),
    getItem('软件工程基础', '15'),
    getItem('软件需求工程', '16'),
    getItem('软件工程管理', '17'),
    getItem('软件质量保证与测试', '18'),
    getItem('操作系统', '19'),
    getItem('计算机网络', '20'),
    getItem('B/S体系软件设计', '21'),
    getItem('Java程序设计', '22'),
    getItem('程序设计方法学', '23'),
    getItem('嵌入式系统', '24'),
    getItem('汇编与接口', '25'),
    getItem('区块链与数字货币', '26'),
    getItem('国际证券市场导论', '27'),
  ]),
];

// submenu keys of first level
const rootSubmenuKeys = ['sub1'];
const Sidebar = () => {
  const [openKeys, setOpenKeys] = useState(['sub1']);
  const onOpenChange = (keys) => {
    const latestOpenKey = keys.find((key) => openKeys.indexOf(key) === -1);
    if (rootSubmenuKeys.indexOf(latestOpenKey) === -1) {
      setOpenKeys(keys);
    } else {
      setOpenKeys(latestOpenKey ? [latestOpenKey] : []);
    }
  };
  const onLink = (key) => {
    console.log(key.key)
    // switch(key) {
    //   case '1':
    //     window.location.href = "./introduction";
    //     break;
    //   case '19':
    //     console.log('yes')
    //     window.location.href = "./OS"
    //     break;
    //   default :
    //     break;
    // }
    if (key.key == '1') {
      window.location.href = "./introduction"
    }
    else if (key.key == '19') {
      window.location.href = "./OS"
    }
    else {
      console.log('no')
      //window.location.href = "./OS"
    }
  };
  return (
    <Menu
      mode="inline"
      openKeys={openKeys}
      onOpenChange={onOpenChange}
      style={{
        width: 256,
      }}
      items={items}
      onClick={onLink}
    />
  );
};

export default Sidebar;